package com.itheima.reggie.utils;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

@Data
@ApiModel("通用返回结果")
public class Result<E> implements Serializable {
    @ApiModelProperty("状态码")
    private Integer code;
    @ApiModelProperty("数据")
    private E data;
    @ApiModelProperty("信息")
    private String msg;

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.code = 1;
        result.data = data;
        return result;
    }


    public static <E> Result<E> error(String msg) {
        Result<E> result = new Result<>();
        result.code = 0;
        result.msg = msg;
        return result;
    }
}
